<!--
	登录页面
-->
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>JZ-energy</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link rel="stylesheet" type="text/css" href="../css/mui.min.css"/>
		<link rel="stylesheet" type="text/css" href="../css/public.css"/>
		<link rel="stylesheet" type="text/css" href="../css/icons-extra.css" />
		<script src="../js/jquery.min.js"></script>
		<script src="../js/login.js"></script>
		<style type="text/css">
			html,body {width: 100%; height: 100%;}
			.mui-input-group {background-color: transparent;}
			input::-webkit-input-placeholder { color:#BDBDBD; font-size: 14px;}
			.main-form label {width: 20%;}
			.main-form label~input {width: 80%;}
			.mui-input-group:before,.mui-input-group:after,.mui-input-group .mui-input-row:after {height: 0px;}
			.main-form .mui-input-row {height: 35px;}
			#username,#password  {height: 35px;}
			.mui-input-row label {padding: 9px 15px;}
			.mui-input-row .mui-input-clear~.mui-icon-clear {top: 7px; color: #BDBDBD;}
			.remerable .mui-input-row {height: 50px;}
			.remerable .mui-input-row label {padding: 17px 15px;}
			.remerable input {height: 50px;}
		</style>
	</head>
	<body>
		<div class="mui-content login-wrap">
			<form class="main-form mui-input-group wh-100">
				<div style="padding: 24% 0 15% 0;text-align: center;">
					<img src="../img/logo1.png" height="45"/>
				</div>
				<div class="mui-input-row login-box">
					<label for="username">
						<img src="../img/user.png" width="15"/>
					</label>
					<input type="url" id="username" class="mui-input-clear mui-input col-fonts" placeholder="请输入用户名">
				</div>
				<div class="mui-input-row login-box">
					<label for="password">
						<img src="../img/password.png" width="15"/>
					</label>
					<input type="password" id="password" class="mui-input-clear mui-input col-fonts" placeholder="请输入密码">
				</div>
				<div class="nameDiv btnLogin" onclick="logSrv.login()">登   &nbsp; 录</div>
				<div class="find-pwd-box font-12">
					<span class="col-blue" onclick="findPwd()">忘记密码？</span>
				</div>
				<div class="btnLogin reserved">
					<img src="../img/ZS-LOGO.png" width="40px" class="d-lb ver-md"/>
					<div class="font-12 col-fonts d-lb ver-md" style="margin-left: 5px;">©2017-2018</div>
					<div class="col-blue font-12 d-lb ver-md">www.jzene.com</div>
					<div class="font-12 col-fonts d-lb ver-md">All rights reserved</div>
				</div>
			</form>
			<div class="remerable wh-100">
				<!--头部导航栏-->
				<header class="mui-bar mui-bar-nav bg-FFF header-bom">
					<a href="" class="mui-icon-extra mui-icon-extra-arrowleftcricle mui-pull-left col-fonts"></a>
					<h1 class="mui-title col-fonts">找回密码</h1>
				</header>
				<div class="mui-content" style="background: transparent;">
					<form class="mui-input-group af-he be-he" id="forget">
						<div class="mui-input-row col-fonts af-he line2 font-15">
							<label for="">用户</label>
							<input type="url" value="" id="loginame"  placeholder="请输入登录名" class="font-15"/>
						</div>
						<div class="mui-input-row col-fonts af-he line2 font-15">
							<label for="">验证码</label>

							<input type="text" value=""  id="validate"  placeholder="请输入验证码" class="font-15"/>
							<div class="mui-btn input_check col-gog" onclick="sendvail(this)" style="width: auto;">获取</div>

						</div>
						<div class="mui-input-row col-fonts af-he line2 font-15">
							<label for="">新密码</label>
							<input type="password" value="" id="newpass" disabled="disabled"  placeholder="请输入新密码" class="font-15" disabled="true"/>
						</div>
						<div class="mui-input-row col-fonts af-he line2 font-15">
							<label for="">确认密码</label>
							<input type="password" value=""  id="repass" disabled="disabled"  placeholder="确认密码" class="font-15" disabled="true"/>
						</div>
					</form>
					<div class="mui-content-padded submitBtn">
						<button type="button" class="mui-btn mui-btn-block submit-btn col-FFF font-15" onclick="updatePWD()">确定</button>
					</div>
				</div>
			</div>
		</div>
	</body>
	<script  src="../js/mui.min.js"></script>
	<script type="text/javascript">
		 mui.back=function () {
	        var btnArray = ['是', '否'];
			if(confirm('退出SolarFos?')){
				plus.runtime.quit();
			}
			throw "不关闭窗体";
  		}

		//关闭除了当前页面的所有webview
		function claerd(){
	        var all = plus.webview.all();
	        var launch = plus.webview.currentWebview();
	        
	        for(var i = 0; i < all.length; i++) {
	            if(all[i] == launch)
	                continue;
	            all[i].close();
	            all[i].clear();
	        }
	        var uname = localStorage.getItem("username");
			var pward = localStorage.getItem("password");
			if(uname && pward){
				$("#username").val(uname);
				$("#password").val(pward);
				if(param.islog)logSrv.login();
			}
		}
		 // H5 plus事件处理
		function plusReady(){
			
		  // 设置系统状态栏背景和字体颜色
		  plus.navigator.setStatusBarBackground('#ffffff');
		  plus.navigator.setStatusBarStyle('dark');
		  param.islog || (location.href = "login.html?islog=1");
		  if(param.islog)claerd();
		}
		if(window.plus){
		  	plusReady();
		}else{
		  	document.addEventListener('plusready', plusReady, false);
		}
		
		//找回密码
		function findPwd() {
			$(".main-form").hide();
			$(".remerable").show();
			$("#forget").find("input").val("");
			
		}
		//发送邮件
		//找回密码
		var re = /^([a-zA-Z0-9_\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	
		 //发送验证码 
		 var message = ["","该用户不存在！","请输入用户名！","","发送失败,请联系管理员!","该用户无绑定邮箱，请联系管理员!"];
		function getValidate(){
		
			var username = $("#loginame").val();
			var vtime= localStorage.getItem("vtime");
			var flag = false;
			if(username){
				$.ajax({
					url:serverHost+"/mobile/send",
					async:false,
					dataType:"text",
					data:{
						"username":username
					},
					success:function(data){
						if(data.indexOf("?")>-1){
							var valinum = data.split("?")[1];
							localStorage.setItem("valite",valinum);
							localStorage.setItem("vtime",new Date().getTime());
							mui.alert("验证码已发送请及时查收","提示","确认");
							flag=true;
						}else{
							mui.alert(message[parseInt(data)],"提示","确认");
						}
					}
				})
			}
			return flag;
		}
		
		function updatePWD() {
			var email = $("#mail").val();
			var username = $("#loginame").val();
			var pass = $("#newpass").val();
			var repass = $("#repass").val();
			if(username==""){
				mui.alert("请输入用户名","提示","确认");
				return;
			}
			if(pass==""){
				mui.alert("请输入密码","提示","确认");
				return;
			}
			if(pass!=repass){
				mui.alert("两次输入密码不一致","提示","确认");
				return;
			}
			$.ajax({
				url:serverHost+"/mobile/pass",
				dataType:"text",
				data:{"username":username,
					"newpass":pass
				},
				success:function(data){
					if(data=="true"){
						localStorage.setItem("valite","");
						mui.alert("修改密码成功！","提示","确认",function(){
							$(".main-form").show();
							$(".remerable").hide();
							$("#newpass,#repass").attr("disabled","disabled");
						});
						
						
					}else{
						mui.alert("密码修改失败请联系管理员！","提示","确认");
					}
				}
			})
		}
		//验证验证码
		$("#validate").off("blur");
		$("#validate").blur(function(){
			var valid = $(this).val();
			var vtime = localStorage.getItem("vtime");
			if(valid){
				if(valid!="" && valid==localStorage.getItem("valite")){
					if(new Date().getTime()>new Date(+vtime+5*60*1000).getTime()){
						$("#newpass,#repass").attr("disabled","disabled");
						mui.alert("验证码失效,请重新发送","提示","确认")
					}else{
						mui.alert("验证通过","提示","确认",function(){
							$("#newpass,#repass").attr("disabled",false);  
							$("#newpass").focus();
						});
					}
				}else{
					$("#newpass,#repass").attr("disabled","disabled");
					mui.alert("验证码错误！","提示","确认");
				}
			}
		})
		
	//间隔60重新发送
	var time = 60;
	function regetval(e){
		if(time==0){
			$(e).attr("onclick","sendvail(this)");
			$(e).html("获取");
			time = 60;
		}else{
			$(e).attr("onclick","");
			$(e).html("重新获取("+time+")");
			time--;
			setTimeout(function(){
				regetval(e);
			},1000);
		}
	}
	function sendvail(e){
		var usernaem = $("#loginame").val();
		if(usernaem==""){
			mui.alert("请输入用户名！","错误提示","确认",function(){
				$("#loginame").focus();
			});
			return;
		}
		if(getValidate())
			regetval(e);
	}
	</script>
</html>